package com.km.team.phsystem.web.interceptor;

import com.km.team.phsystem.service.ISessionProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Author: jiangjun
 * Date: 2018/9/19
 * Time: 下午2:22
 * Description:验证登录拦截器
 */
//@Component
public class LoginInterceptor extends HandlerInterceptorAdapter {

    @Autowired
    private ISessionProvider sessionProvider;


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String requestUri = request.getRequestURI();
        // 不执行登录拦截的url
        /*if(!CollectionUtils.isEmpty(systemConfig.getNonLoginUrls())){
            for (String nonLoginUrl : systemConfig.getNonLoginUrls()){
                if(requestUri.contains(nonLoginUrl)){
                    return true;
                }
            }
        }*/
//        String csessionid = RequestUtils.getCSESSIONID(request, response);
//        if (StringUtils.isNotBlank(csessionid)) {
//            WxTokenResult session = sessionProvider.getSession(csessionid);
//            if(session != null) {
//                // 身份信息存在，放行
//                return true;
//            }
//        }
        // 执行到此处表示用户身份需要认证，跳转到登录页面
//        request.getRequestDispatcher("/toLoginUI")
//                .forward(request,response);
//        response.setStatus(HttpStatus.NON_AUTHORITATIVE_INFORMATION.value());
//        return false;
        return true;
    }
}
